package zhouzhouyongche.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import zhouzhouyongche.model.Day;
import zhouzhouyongche.model.Year;

@Repository
public class YearDao extends HibernateDao<Year> {

	public Year getOrAdd(int year) {
		Year result = null;
		String hql = "from Year as y where y.year = ?";
		Query q = getCurrentSession().createQuery(hql);
		q.setInteger(0, year);
		List yearList = q.list();
		if (yearList.size() == 0) {
			Year yearObj = new Year();
			yearObj.setYear(year);
			this.save(yearObj);
			
			String _hql = "from Year as y where y.year = ?";
			Query _q = getCurrentSession().createQuery(_hql);
			_q.setInteger(0, year);
			result = (Year)q.list().get(0);
		} else {
			result = (Year)yearList.get(0);
		}
		return result;
	}
	
}
